package com.itfreer.gather.setting;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.itfreer.data.config.ConfigService;
import com.itfreer.gather.R;
import com.itfreer.ui.activity.BaseActivity;
import com.itfreer.ui.base.checkbox.CheckBoxTextView;
import com.itfreer.ui.base.EditText;
import com.itfreer.ui.base.TextView;
import com.itfreer.utils.config.ConfigManager;

/**
 * 网络设置
 */
public class NetworkActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting_network_activity);

        // 返回
        TextView me =(TextView)findViewById(R.id.setting_network_back);
        me.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });

        final EditText httpUrl =(EditText)findViewById(R.id.setting_network_httpurl);
        httpUrl.setText(ConfigManager.getConfig("HttpUrl").toString());
//        httpUrl.setText("http://47.95.220.20:81/development");
        final CheckBoxTextView g3LocalUpload =(CheckBoxTextView)findViewById(R.id.setting_network_g3uploadlocal);
        g3LocalUpload.setChecked((boolean)ConfigManager.getConfig("G3LocalUpload"));

        final CheckBoxTextView g3DataUpload =(CheckBoxTextView)findViewById(R.id.setting_network_g3uploaddata);
        g3DataUpload.setChecked((boolean)ConfigManager.getConfig("G3DataUpload"));

        Button save =(Button)findViewById(R.id.setting_network_save);
        save.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ConfigManager.setConfig("HttpUrl", httpUrl.getText());
                ConfigManager.setConfig("G3LocalUpload", g3LocalUpload.getChecked());
                ConfigManager.setConfig("G3DataUpload", g3DataUpload.getChecked());
                ConfigService.instance.update();
                finish();
            }
        });
    }
}
